package com.yoomiito.app.adapter.cicle;

import androidx.annotation.Nullable;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.request.RequestOptions;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.yoomiito.app.R;
import com.yoomiito.app.base.App;
import com.yoomiito.app.model.cicle.ImageItemBean;
import com.yoomiito.app.utils.SpannableUtils;

import java.util.List;

public class ImageAdapter extends BaseQuickAdapter<ImageItemBean, BaseViewHolder> {
    public ImageAdapter(@Nullable List<ImageItemBean> data) {
        super(R.layout.item_image, data);
    }

    @Override
    protected void convert(final BaseViewHolder helper, ImageItemBean item) {
        RequestOptions requestOptions = new RequestOptions();
        requestOptions.placeholder(R.drawable.goods_default);
        Glide.with(App.getApplication()).load(item.getUrl()).apply(requestOptions).into((ImageView)helper.getView(R.id.iv_photo));
        helper.addOnClickListener(R.id.iv_photo);
        TextView tv = helper.getView(R.id.item_image_price);
        if(SpannableUtils.isEmptyOr0(item.getPrice())){
            tv.setVisibility(View.GONE);
        }else {
            tv.setText("¥"+SpannableUtils.handlePrice(item.getPrice()));
        }

    }
}
